(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

minus(x, y) → cond(gt(x, y), x, y)
cond(false, x, y) → 0
cond(true, x, y) → s(minus(x, s(y)))
gt(0, v) → false
gt(s(u), 0) → true
gt(s(u), s(v)) → gt(u, v)

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

minus(x, y) → cond(gt(x, y), x, y) [1]
cond(false, x, y) → 0 [1]
cond(true, x, y) → s(minus(x, s(y))) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

minus(x, y) → cond(gt(x, y), x, y) [1]
cond(false, x, y) → 0 [1]
cond(true, x, y) → s(minus(x, s(y))) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]

The TRS has the following type information:
minus :: 0:s → 0:s → 0:s
cond :: false:true → 0:s → 0:s → 0:s
gt :: 0:s → 0:s → false:true
false :: false:true
0 :: 0:s
true :: false:true
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

minus(x, y) → cond(gt(x, y), x, y) [1]
cond(false, x, y) → 0 [1]
cond(true, x, y) → s(minus(x, s(y))) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]

The TRS has the following type information:
minus :: 0:s → 0:s → 0:s
cond :: false:true → 0:s → 0:s → 0:s
gt :: 0:s → 0:s → false:true
false :: false:true
0 :: 0:s
true :: false:true
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

false => 0
0 => 0
true => 1

(8) Obligation:

Complexity RNTS consisting of the following rules:

cond(z, z', z'') -{ 1 }→ 0 :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
cond(z, z', z'') -{ 1 }→ 1 + minus(x, 1 + y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
gt(z, z') -{ 1 }→ gt(u, v) :|: v >= 0, z' = 1 + v, z = 1 + u, u >= 0
gt(z, z') -{ 1 }→ 1 :|: z = 1 + u, z' = 0, u >= 0
gt(z, z') -{ 1 }→ 0 :|: v >= 0, z' = v, z = 0
minus(z, z') -{ 1 }→ cond(gt(x, y), x, y) :|: x >= 0, y >= 0, z = x, z' = y

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V4),0,[minus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V4),0,[cond(V, V1, V4, Out)],[V >= 0,V1 >= 0,V4 >= 0]).
eq(start(V, V1, V4),0,[gt(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(minus(V, V1, Out),1,[gt(V2, V3, Ret0),cond(Ret0, V2, V3, Ret)],[Out = Ret,V2 >= 0,V3 >= 0,V = V2,V1 = V3]).
eq(cond(V, V1, V4, Out),1,[],[Out = 0,V1 = V5,V4 = V6,V5 >= 0,V6 >= 0,V = 0]).
eq(cond(V, V1, V4, Out),1,[minus(V7, 1 + V8, Ret1)],[Out = 1 + Ret1,V1 = V7,V4 = V8,V = 1,V7 >= 0,V8 >= 0]).
eq(gt(V, V1, Out),1,[],[Out = 0,V9 >= 0,V1 = V9,V = 0]).
eq(gt(V, V1, Out),1,[],[Out = 1,V = 1 + V10,V1 = 0,V10 >= 0]).
eq(gt(V, V1, Out),1,[gt(V11, V12, Ret2)],[Out = Ret2,V12 >= 0,V1 = 1 + V12,V = 1 + V11,V11 >= 0]).
input_output_vars(minus(V,V1,Out),[V,V1],[Out]).
input_output_vars(cond(V,V1,V4,Out),[V,V1,V4],[Out]).
input_output_vars(gt(V,V1,Out),[V,V1],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [gt/3]
1. recursive : [cond/4,minus/3]
2. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into gt/3
1. SCC is partially evaluated into minus/3
2. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations gt/3
* CE 10 is refined into CE [11]
* CE 9 is refined into CE [12]
* CE 8 is refined into CE [13]


### Cost equations --> "Loop" of gt/3
* CEs [12] --> Loop 8
* CEs [13] --> Loop 9
* CEs [11] --> Loop 10

### Ranking functions of CR gt(V,V1,Out)
* RF of phase [10]: [V,V1]

#### Partial ranking functions of CR gt(V,V1,Out)
* Partial RF of phase [10]:
- RF of loop [10:1]:
V
V1


### Specialization of cost equations minus/3
* CE 7 is refined into CE [14,15]
* CE 6 is refined into CE [16,17]


### Cost equations --> "Loop" of minus/3
* CEs [17] --> Loop 11
* CEs [16] --> Loop 12
* CEs [15] --> Loop 13
* CEs [14] --> Loop 14

### Ranking functions of CR minus(V,V1,Out)
* RF of phase [11]: [V-V1]

#### Partial ranking functions of CR minus(V,V1,Out)
* Partial RF of phase [11]:
- RF of loop [11:1]:
V-V1


### Specialization of cost equations start/3
* CE 2 is refined into CE [18,19,20]
* CE 3 is refined into CE [21]
* CE 4 is refined into CE [22,23,24,25,26]
* CE 5 is refined into CE [27,28,29,30]


### Cost equations --> "Loop" of start/3
* CEs [26,30] --> Loop 15
* CEs [20] --> Loop 16
* CEs [19,25,29] --> Loop 17
* CEs [18,23,24,28] --> Loop 18
* CEs [21,22,27] --> Loop 19

### Ranking functions of CR start(V,V1,V4)

#### Partial ranking functions of CR start(V,V1,V4)


Computing Bounds
=====================================

#### Cost of chains of gt(V,V1,Out):
* Chain [[10],9]: 1*it(10)+1
Such that:it(10) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [[10],8]: 1*it(10)+1
Such that:it(10) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [9]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [8]: 1
with precondition: [V1=0,Out=1,V>=1]


#### Cost of chains of minus(V,V1,Out):
* Chain [[11],13]: 3*it(11)+1*s(1)+1*s(4)+3
Such that:it(11) =< Out
aux(2) =< V1+Out
s(1) =< aux(2)
s(4) =< it(11)*aux(2)

with precondition: [V=Out+V1,V1>=1,V>=V1+1]

* Chain [14]: 3
with precondition: [V=0,Out=0,V1>=0]

* Chain [13]: 1*s(1)+3
Such that:s(1) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [12,[11],13]: 4*it(11)+1*s(4)+6
Such that:aux(3) =< Out
it(11) =< aux(3)
s(4) =< it(11)*aux(3)

with precondition: [V1=0,V=Out,V>=2]

* Chain [12,13]: 1*s(1)+6
Such that:s(1) =< 1

with precondition: [V=1,V1=0,Out=1]


#### Cost of chains of start(V,V1,V4):
* Chain [19]: 3
with precondition: [V=0,V1>=0]

* Chain [18]: 1*s(5)+4*s(7)+1*s(8)+6
Such that:s(5) =< 1
s(6) =< V
s(7) =< s(6)
s(8) =< s(7)*s(6)

with precondition: [V1=0,V>=1]

* Chain [17]: 1*s(9)+2*s(10)+4
Such that:s(9) =< V1
aux(4) =< V
s(10) =< aux(4)

with precondition: [V>=1,V1>=V]

* Chain [16]: 3*s(12)+1*s(14)+1*s(15)+4
Such that:s(13) =< V1
s(12) =< V1-V4
s(14) =< s(13)
s(15) =< s(12)*s(13)

with precondition: [V=1,V4>=0,V1>=V4+2]

* Chain [15]: 3*s(16)+1*s(18)+1*s(19)+1*s(20)+3
Such that:s(17) =< V
s(16) =< V-V1
s(20) =< V1
s(18) =< s(17)
s(19) =< s(16)*s(17)

with precondition: [V1>=1,V>=V1+1]


Closed-form bounds of start(V,V1,V4):
-------------------------------------
* Chain [19] with precondition: [V=0,V1>=0]
- Upper bound: 3
- Complexity: constant
* Chain [18] with precondition: [V1=0,V>=1]
- Upper bound: 4*V+7+V*V
- Complexity: n^2
* Chain [17] with precondition: [V>=1,V1>=V]
- Upper bound: 2*V+V1+4
- Complexity: n
* Chain [16] with precondition: [V=1,V4>=0,V1>=V4+2]
- Upper bound: 3*V1-3*V4+ (V1+4+ (V1-V4)*V1)
- Complexity: n^2
* Chain [15] with precondition: [V1>=1,V>=V1+1]
- Upper bound: 3*V-3*V1+ (V+3+ (V-V1)*V+V1)
- Complexity: n^2

### Maximum cost of start(V,V1,V4): max([max([V+1+max([V1,2*V+3+V*V]),nat(V-V1)*V+V1+nat(V-V1)*3])+V,V1+1+nat(V1-V4)*V1+nat(V1-V4)*3])+3
Asymptotic class: n^2
* Total analysis performed in 192 ms.

(10) BOUNDS(1, n^2)